<?php
class BuildController extends ZendX_Controller_Action_None {
	public function indexAction() {
		$config = ZendX_Config_Manager::getInstance()->getConfig('layout', 'development');

		$script_time = microtime(true);
		$script_content = '';
		foreach($config->scripts->items as $item) {
			if(!isset($item->compile)) {
				continue;
			}
			if(!$item->compile) {
				continue;
			}
			$script_content .= file_get_contents(APPLICATION_PATH . '/../public' ."{$config->scripts->baseDir}/{$item->path}");
		}
		if(strlen($script_content) > 0) {
			$pack = new ZendX_Build_Js($script_content);
			file_put_contents(APPLICATION_PATH . '/../public'. "{$config->scripts->baseDir}/compiled.js", $pack->pack());
		}
		$script_time = microtime(true) - $script_time;

		printf("Packing script done in: %.04f\n", $script_time);

		$style_time = microtime(true);
		$style_content = '';
		foreach($config->styles->items as $item) {
			if(!isset($item->compile)) {
				continue;
			}
			if(!$item->compile) {
				continue;
			}
			$style_content .= file_get_contents(APPLICATION_PATH . '/../public' ."{$config->styles->baseDir}/{$item->path}");
		}
		if(strlen($style_content) > 0) {
			$pack = new ZendX_Build_Css();
			file_put_contents(APPLICATION_PATH . '/../public'. "{$config->styles->baseDir}/compiled.css", $pack->parse($style_content));
		}
		$style_time = microtime(true) - $style_time;

		printf("Packing style done in: %.04f\n", $script_time);
	}
}